home *** CD-ROM | disk | FTP | other *** search
/ Mastering Computers 3 / Mastering Computers Vol 3.iso / Browser / browse.dxr / 00002_path class.ls < prev    next >
Encoding:
Text File  |  1996-11-01  |  3.3 KB  |  130 lines

  1. property mainPath, oldPath, currentPath, newPath, directory, theFile, theFolder, delim, pathToFile, fileToCopy, contentList, lineOffset
  2.  
  3. on new me, gDelim, thePath, theDirectory
  4.   set delim to gDelim
  5.   set mainPath to thePath
  6.   set currentPath to mainPath
  7.   set directory to theDirectory
  8.   set lineOffset to 0
  9.   return me
  10. end
  11.  
  12. on setFile_Folder me
  13.   set folderName to directory
  14.   set fileName to directory & ".tx`"
  15.   setPath(me, folderName, fileName)
  16.   put folderName into field "display1"
  17.   put lookup(me) into field "display2"
  18. end
  19.  
  20. on setPath me, folderName, fileName
  21.   set newPath to currentPath & folderName & delim
  22.   set theFile to fileName
  23.   set pathToFile to newPath & fileName
  24.   put newPath into field "path"
  25.   set currentPath to newPath
  26. end
  27.  
  28. on lookup me
  29.   set text1 to EMPTY
  30.   set tempFiles to []
  31.   set tempFolders to []
  32.   sort(tempFiles)
  33.   sort(tempFolders)
  34.   repeat with n = 1 to the maxinteger
  35.     set file to getNthFileNameInFolder(newPath, n)
  36.     if file = EMPTY then
  37.       exit repeat
  38.     end if
  39.     if file = theFile then
  40.       next repeat
  41.       next repeat
  42.     end if
  43.     set the itemDelimiter to "."
  44.     if the number of items in file > 1 then
  45.       add(tempFiles, file)
  46.       next repeat
  47.     end if
  48.     add(tempFolders, file)
  49.   end repeat
  50.   set lineOffset to count(tempFolders)
  51.   repeat with i = 1 to count(tempFolders)
  52.     put getAt(tempFolders, i) & RETURN after text1
  53.   end repeat
  54.   repeat with i = 1 to count(tempFiles)
  55.     put getAt(tempFiles, i) & RETURN after text1
  56.   end repeat
  57.   return text1
  58. end
  59.  
  60. on goBackOneLevel me
  61.   set the itemDelimiter to delim
  62.   set i to the number of items in currentPath
  63.   delete item i - 1 to i of currentPath
  64.   set oldPath to currentPath & delim
  65.   if oldPath = mainPath then
  66.     goMenu()
  67.   end if
  68.   set folderName to item i - 2 of currentPath
  69.   set theFile to folderName & ".tx`"
  70.   set pathToFile to oldPath & theFile
  71.   set currentPath to oldPath
  72.   set newPath to oldPath
  73.   put folderName into field "display1"
  74.   put lookup(me) into field "display2"
  75.   makeDescriptionList()
  76.   put currentPath into field "path"
  77.   put EMPTY into field "description"
  78. end
  79.  
  80. on makeDescriptionList me
  81.   set file to new(xtra("FileIO"))
  82.   set txtFile to pathToFile
  83.   openFile(file, txtFile, 1)
  84.   set tempText to " "
  85.   set description to []
  86.   set tempText to readFile(file)
  87.   if voidp(tempText) then
  88.     return 
  89.   end if
  90.   repeat with i = 1 to the number of lines in tempText
  91.     if i = 1 then
  92.       set aLine to line i of tempText
  93.       add(description, aLine)
  94.       next repeat
  95.     end if
  96.     set aLine to line i of tempText
  97.     delete char 1 of aLine
  98.     add(description, aLine)
  99.   end repeat
  100.   closeFile(file)
  101.   set file to 0
  102.   return description
  103. end
  104.  
  105. on copyFile me
  106.   if not (fileToCopy contains ".") then
  107.     return 
  108.   end if
  109.   set NameOfFile to currentPath & fileToCopy
  110.   if NameOfFile = currentPath then
  111.     return 
  112.   end if
  113.   set file to new(xtra("FileIO"))
  114.   set fileToDisk to displaySave(file, "Choose a destination for:", fileToCopy)
  115.   set fileFromCD to NameOfFile
  116.   if fileToDisk = EMPTY then
  117.     return 
  118.   else
  119.     if the machineType = 256 then
  120.       openXLib("ProgCopy.x32")
  121.     else
  122.       openXLib("ProgressCopy Xtra (FAT)")
  123.     end if
  124.     set pcObj to new(xtra("ProgressCopy"), 1, 1, 1)
  125.     copyFile(pcObj, fileFromCD, fileToDisk, 1, 1, 1)
  126.     set pcObj to 0
  127.     set file to 0
  128.   end if
  129. end
  130.